package com.aphrodite.io.sip.message;

import com.aphrodite.io.sip.header.AllowEventsHeader;
import com.aphrodite.io.sip.header.EventHeader;
import com.aphrodite.io.sip.header.Header;
import com.aphrodite.io.sip.header.ReferToHeader;
import com.aphrodite.io.sip.header.ReferredByHeader;
import com.aphrodite.io.sip.header.SipHeaders;
import com.aphrodite.io.sip.header.SubscriptionStateHeader;
import com.aphrodite.io.sip.net.UdpPacket;

/**
 * Class Message extends class sip.message.BaseMessage adding some SIP
 * extensions. <p /> Class Message supports all methods and header definened in
 * RFC3261, plus:
 * <ul>
 * <li>method MESSAGE (RFC3428) </>
 * <li>method REFER (RFC3515) </>
 * <li>header Refer-To </>
 * <li>header Referred-By </>
 * <li>header Event </>
 * </ul>
 */
// public class Message extends org.zoolu.sip.message.BaseMessage
public final class Message extends com.aphrodite.io.sip.message.BaseMessageOtp {
	/** Costructs a new empty Message */
	public Message() {
		super();
	}

	/** Costructs a new Message */
	public Message(byte[] buff, int offset, int len) {
		super(buff, offset, len);
	}

	/** Costructs a new Message */
	public Message(Message msg) {
		super(msg);
	}

	/** Costructs a new Message */
	public Message(String str) {
		super(str);
	}

	/** Costructs a new Message */
	public Message(UdpPacket packet) {
		super(packet);
	}

	/** Creates and returns a clone of the Message */
	public Object clone() {
		return new Message(this);
	}

	// ****************************** Extensions
	// *******************************/

	/** Gets AllowEventsHeader */
	public AllowEventsHeader getAllowEventsHeader() {
		Header h = getHeader(SipHeaders.Allow_Events);
		if (h == null)
			return null;
		return new AllowEventsHeader(h);
	}

	/** Gets EventHeader */
	public EventHeader getEventHeader() {
		Header h = getHeader(SipHeaders.Event);
		if (h == null)
			return null;
		return new EventHeader(h);
	}

	/** Gets ReferredByHeader */
	public ReferredByHeader getReferredByHeader() {
		Header h = getHeader(SipHeaders.Referred_By);
		if (h == null)
			return null;
		return new ReferredByHeader(h);
	}

	/** Gets ReferToHeader */
	public ReferToHeader getReferToHeader() {
		Header h = getHeader(SipHeaders.Refer_To);
		if (h == null)
			return null;
		return new ReferToHeader(h);
	}

	/** Gets SubscriptionStateHeader */
	public SubscriptionStateHeader getSubscriptionStateHeader() {
		Header h = getHeader(SipHeaders.Subscription_State);
		if (h == null)
			return null;
		return new SubscriptionStateHeader(h);
	}

	/** Whether the message has the AllowEventsHeader */
	public boolean hasAllowEventsHeader() {
		return hasHeader(SipHeaders.Allow_Events);
	}

	/** Whether the message has the EventHeader */
	public boolean hasEventHeader() {
		return hasHeader(SipHeaders.Event);
	}

	/** Whether the message has the Referred-By header */
	public boolean hasReferredByHeader() {
		return hasHeader(SipHeaders.Refer_To);
	}

	/** Whether the message has the Refer-To header */
	public boolean hasReferToHeader() {
		return hasHeader(SipHeaders.Refer_To);
	}

	/** Whether the message has the Subscription-State header */
	public boolean hasSubscriptionStateHeader() {
		return hasHeader(SipHeaders.Subscription_State);
	}

	/**
	 * Returns boolean value to indicate if Message is a MESSAGE request
	 * (RFC3428)
	 */
	public boolean isMessage() throws NullPointerException {
		return isRequest(SipMethods.MESSAGE);
	}

	/**
	 * Returns boolean value to indicate if Message is a NOTIFY request
	 * (RFC3265)
	 */
	public boolean isNotify() throws NullPointerException {
		return isRequest(SipMethods.NOTIFY);
	}

	/**
	 * Returns boolean value to indicate if Message is a PUBLISH request
	 * (RFC3903)
	 */
	public boolean isPublish() throws NullPointerException {
		return isRequest(SipMethods.PUBLISH);
	}

	/**
	 * Returns boolean value to indicate if Message is a REFER request (RFC3515)
	 */
	public boolean isRefer() throws NullPointerException {
		return isRequest(SipMethods.REFER);
	}

	/**
	 * Returns boolean value to indicate if Message is a SUBSCRIBE request
	 * (RFC3265)
	 */
	public boolean isSubscribe() throws NullPointerException {
		return isRequest(SipMethods.SUBSCRIBE);
	}

	/** Removes AllowEventsHeader from Message (if it exists) */
	public void removeAllowEventsHeader() {
		removeHeader(SipHeaders.Allow_Events);
	}

	/** Removes EventHeader from Message (if it exists) */
	public void removeEventHeader() {
		removeHeader(SipHeaders.Event);
	}

	/** Removes ReferredByHeader from Message (if it exists) */
	public void removeReferredByHeader() {
		removeHeader(SipHeaders.Referred_By);
	}

	/** Removes ReferToHeader from Message (if it exists) */
	public void removeReferToHeader() {
		removeHeader(SipHeaders.Refer_To);
	}

	/** Removes SubscriptionStateHeader from Message (if it exists) */
	public void removeSubscriptionStateHeader() {
		removeHeader(SipHeaders.Subscription_State);
	}

	/** Sets AllowEventsHeader */
	public void setAllowEventsHeader(AllowEventsHeader h) {
		setHeader(h);
	}

	/** Sets EventHeader */
	public void setEventHeader(EventHeader h) {
		setHeader(h);
	}

	/** Sets ReferredByHeader */
	public void setReferredByHeader(ReferredByHeader h) {
		setHeader(h);
	}

	/** Sets ReferToHeader */
	public void setReferToHeader(ReferToHeader h) {
		setHeader(h);
	}

	/** Sets SubscriptionStateHeader */
	public void setSubscriptionStateHeader(SubscriptionStateHeader h) {
		setHeader(h);
	}

}
